package com.example.java.designpattern;

/**
 * @author zengty
 * @apiNote 责任链
 * @date 2024/8/29
 * @project study
 */
public class RespChainDivisor implements Divisor {

    private final Divisor divisor;

    private RespChainDivisor next;

    public RespChainDivisor(Divisor divisor) {
        this.divisor = divisor;
    }

    public void setNext(RespChainDivisor next) {
        this.next = next;
    }

    public RespChainDivisor next() {
        return next;
    }

    @Override
    public void divide(String s){
        if(divisor.isSupport(s)){
            divisor.divide(s);
        }else if(next != null) {
            next.divide(s);
        }else {
            throw new UnsupportedOperationException("Divisor is not supported");
        }
    }
}
